
#ifndef _TLSCONTROLLER_H_
#define _TLSCONTROLLER_H_

#include <string>
#include <map>

class LocalView;
class TimeIncrementCalculationStrategy;

class TLSController {

public:
	TLSController(const char* id, int x, int y);

	virtual ~TLSController();

	/**
	 * Add a new street that is part of this TLS
	 */
	void addStreet(const char* streetName, int direction);

	/**
	 * Store data retrieved from street sensors
	 */
	void updateStreetSensors(const char* streetName, int flush, int queueSize);

	/**
	 * Add a controller as neighbor of this one.
	 *
	 * @param address used to send data to this neighbor
	 * @param streetName name of edge that join current controller with its new neighbor
	 * @param id Identifies the neighbor.
	 */
	void addNeighbor(const char* address, const char* streetName, const char* id, int direction, int x, int y);

	/**
	 * Create a new thread to calculate green time increment for the phase identified by phaseId
	 *
	 * @param phaseId Integer that identify the phase which extension must be calculated
	 */
	void startPhaseIncrementCalc(int phaseId);

	/**
	 * TODO document
	 */
	int getPhaseIncrement(int phaseId);

protected:

	/**
	 * TODO document
	 */
	void registerBackgroundCalcTask(TimeIncrementCalculationStrategy* tics, int phaseId);

	/**
	 * TODO document
	 */
	TimeIncrementCalculationStrategy* unregisterBackgroundCalcTask(int phaseId);

private:
	/**
	 * String that identify this controller.
	 */
	std::string mControllerId;

	/**
	 * This object holds controller local vision.
	 *
	 * All data measured on sensors or received from tls network
	 * are accessible through this object.
	 */
	LocalView* mLocalView;

	/**
	 * Strategy to calculate phase increment
	 */
	std::map<int, TimeIncrementCalculationStrategy*> mActiveCalc;

public:
	static const std::string TAG;
};

#endif
